<template>
    <avue-crud ref="crud"
                :option="option"
                v-model:page="page"
                :table-loading="loading"
                @on-load="getList"
                @row-update="rowUpdate"
                @row-save="rowSave"
                @row-del="rowDel"
                @refresh-change="refreshChange"  
                @search-reset="searchChange"
                @search-change="searchChange"
                v-model="form"
                :data="data">
    </avue-crud>
  </template>
  
  <script>
  import { mapGetters } from "vuex"
  import { getList,update,add,del} from '@/api/notice.js'
  import option from '@/api/notice-option.js'
  export default {
    data () {
      return {
        page: {},
        form: {},
        params: {},
        loading: false,
        data: [],
        option: option(this)
      }
    },
    computed: {
      ...mapGetters(['userInfo'])
    },
    methods: {
      // 列表查询
      getList () {
        this.loading = true
        this.data = []
        getList(1).then(res => {
          this.loading = false
          this.data = res.data
        })
      },
      // 信息模糊查询
      getLinkList(params){
        this.loading = true
        this.data = []
        getLikeList(params).then(res => {
          this.loading = false
          this.data = res.data
        })
      },
      // 新增操作
      rowSave (row, done, loading) {
        add(row).then(() => {
          this.$message.success('新增成功')
          done()
          this.getList()
        }).catch(() => {
          loading()
        })
      },
      // 修改操作
      rowUpdate (row,done,loading) {
        console.log(row)
        update(row).then(() => {
          this.$message.success('修改成功')
          this.getList()
          done()
        }).catch(() => {
          loading()

        })
      },
      // 删除操作
      rowDel (row) {
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          return del(row.id)
        }).then(() => {
          this.$message.success('删除成功')
          this.getList()
        })
      },
      // 搜索刷新
      searchChange (params, done) {

        if (done) done()
        this.params = params
        this.page.currentPage = 1
        this.getLinkList(params)
        this.$message.success('搜索成功')
      },
      refreshChange () {
        this.getList()
        this.$message.success('刷新成功')
      }
    }
  }
  </script>